<!-- 调拨单记录 -->
<template>
  <div id="change">
    <div class="change-top">
      单据编号：
      <el-input size="small" style="width: 240px;margin-left: 10px;margin-right: 20px;" placeholder="请输入单据号"
<<<<<<< HEAD
        v-model="input" clearable>
      </el-input>
      日期：
      <el-date-picker size="small" :unlink-panels="true" v-model="value1" type="daterange" range-separator="至"
        start-placeholder="开始日期" end-placeholder="结束日期">
      </el-date-picker>
      <!-- <el-button size="small" style="margin-left: 10px;" type="primary">查询</el-button>
      <el-button size="small" type="primary" @click="goto('addChange')">新增</el-button>
      <el-button size="small" type="primary">导入</el-button>
      <el-button size="small" type="primary">导出</el-button> -->
      <PublicButton add="addChange" />
    </div>
    <div class="change-content">
      <el-table show-summary :summary-method="getSummaries" height="500px" :data="tableData" border
=======
        v-model="code" clearable>
      </el-input>
      日期：
      <el-date-picker size="small" :unlink-panels="true" v-model="value1" type="daterange" range-separator="至"
        start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
      </el-date-picker>
      <el-button size="small" style="margin-left: 10px;" type="primary" @click="getPage(1, 5)">查询</el-button>
      <el-button size="small" type="primary" @click="goto('addChange')">新增</el-button>
      <el-button size="small" type="primary">导入</el-button>
      <el-button size="small" type="primary">导出</el-button>
      <el-button size="small" type="success">审核</el-button>
      <!-- <el-button size="small" type="danger">删除</el-button> -->
    </div>
    <div class="change-content">
      <el-table show-summary :summary-method="getSummaries" height="500px" :data="pageInfo.list" border
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
        style="width: 100%;font-size: 13px;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="createDate" label="单据日期" width="150">
        </el-table-column>
<<<<<<< HEAD
        <el-table-column prop="goodsId" label="商品编号" width="150">
        </el-table-column>
        <el-table-column prop="code" label="单据编号" width="120">
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="pid" label="业务员" width="120">
        </el-table-column>
        <el-table-column prop="mid" label="制单人" width="300">
        </el-table-column>
        <el-table-column prop="aid" label="审核人" width="120">
        </el-table-column>
        <el-table-column prop="num" label="数量" width="120">
        </el-table-column>
        <el-table-column prop="outWid" label="调出仓库" width="300">
        </el-table-column>
        <el-table-column prop="inputWid" label="调入仓库" width="120">
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="120">
        </el-table-column>
        <el-table-column prop="aboutCode" label="关联调拨订单号" width="120">
        </el-table-column>
        <el-table-column prop="state" label="审核状态" width="300">
        </el-table-column>
        <el-table-column prop="status" label="是否启用" width="120">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status" active-color="#66b1ff" inactive-color="#c1c1c1" active-value="1"
              inactive-value="0">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
            <el-button type="text" size="small">编辑</el-button>
=======
        <el-table-column prop="changeCode" label="单据编号" width="120">
        </el-table-column>
        <el-table-column prop="employeeName" label="业务员" width="120">
        </el-table-column>
        <el-table-column label="商品明细" width="700">
          <template slot-scope="scope">
            <table id="contact-table" style="width: 100%; text-align:center;">
              <tr>
                <th>商品编号</th>
                <th>商品名称</th>
                <th>数量</th>
                <th>单位</th>
                <th>调出仓库</th>
                <th>调入仓库</th>
                <th>备注</th>
              </tr>
              <tr v-for="(detail, index) in scope.row.detailList" :key="index">
                <td>{{ detail.goodcode }}</td>
                <td>{{ detail.goodname }}</td>
                <td>{{ detail.num }}</td>
                <td>{{ detail.unitname }}</td>
                <td>{{ detail.outWidName }}</td>
                <td>{{ detail.inputWidName }}</td>
                <td style="width: 200px;">{{ detail.detailRemark }}</td>
              </tr>
              <tr style="background-color: #fff1d4;color: red;">
                <td>合计</td>
                <td></td>
                <td v-if="sum.id == scope.row.changeId" v-for="(sum, index) in counts" :key="index">{{ sum.sum }}</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
              </tr>
            </table>
          </template>
        </el-table-column>
        <el-table-column prop="mid" label="制单人" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="审核人" width="120">
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="200">
        </el-table-column>
        <!-- <el-table-column prop="aboutCode" label="关联调拨订单号" width="120">
        </el-table-column> -->
        <el-table-column prop="state" label="审核状态" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" circle
              @click="changeListUpdate(scope.row.changeId)"></el-button>
            <el-button type="danger" @click="deleteChangeList(scope.row.changeId)" icon="el-icon-delete"
              circle></el-button>
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
          </template>
        </el-table-column>
      </el-table>

    </div>
<<<<<<< HEAD
    <el-pagination style="width: 400px;position: relative;left: 700px;bottom: 30px;" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :current-page="currentPage4" :page-sizes="[100, 200, 300, 400]"
      :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
=======
    <el-pagination style="width: 400px;position: relative;left: 700px;bottom: 30px;"
      @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize"
      layout="total, prev, pager, next, jumper" :total="pageInfo.total">
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
    </el-pagination>

  </div>
</template>

<script>
import PublicButton from '../public_com/PublicButton.vue';
import AddChange from './AddChange.vue';
export default {
  name: 'ChangeList',
  components: {
    AddChange,
    PublicButton,
  },
  data() {
<<<<<<< HEAD
    return {//分页参数
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
=======
    return {
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
      //新增对话框
      dialogFormVisible: false,
      switchValue: '1',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      input: '',
<<<<<<< HEAD
      tableData: [{
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212'
      },
      {
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212'
      },
      {
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212'
      },
      ],
      value1: '',
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
=======
      value1: '',
      pageInfo: null,
      counts: [],
      code: ''
    }
  },
  methods: {
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    goto(to) {
      this.$router.push(to)
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === "num") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        }
      });

      return sums;
<<<<<<< HEAD
    }

=======
    },
    successMessage(msg) {
      this.$message({
        message: msg,
        type: 'success'
      });
    },
    errorMessage(msg) {
      this.$message({
        message: msg
        ,
        type: 'error'
      })
    },
    getPage(pageNum, pageSize) {
      var params = {
        pageNum,
        pageSize
      }
      if (this.code !== '') {
        params.code = this.code
      }
      if (this.value1 != null) {
        const startTime = this.value1[0]
        const endTime = this.value1[1]
        if (startTime !== '' && endTime != '') {
          params.startTime = startTime
          params.endTime = endTime
        }
      }
      this.axios.get('/store/cl/getChangeListPage', {
        params
      }).then(rs => {
        this.pageInfo = rs.data.pageInfo
        this.getAllCount()
      })
    },
    getAllCount() {
      var list = this.pageInfo.list
      this.counts = []
      list.forEach(item => {
        var detailList = item.detailList
        var sum = 0
        detailList.forEach(detail => {
          sum += parseInt(detail.num)
        })
        this.counts.push({ id: item.changeId, sum })

      })
    },
    deleteChangeList(changeId) {
      this.$confirm('删除该条调拨记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.get('/store/cl/deleteChangeList',
          {
            params: {
              changeId
            }
          }
        ).then(rs => {
          if (rs.data.code == 200) {
            this.successMessage("删除成功")
            this.getPage(1, 5)
          } else {
            this.errorMessage("删除出错了")
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    changeListUpdate(changeId) {
      this.$router.push({
        path: 'updateChangeList',
        query: {
          changeId
        }
      })
    }
  },
  created() {
    this.getPage(1, 5)
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
  }

}
</script>

<style scoped>
#change {
  width: 100%;
  height: 100%;
}

.change-top {
  width: calc(100% -20px);
  height: 60px;
  /* background-color: pink; */
  line-height: 60px;
  padding-left: 20px;
  font-size: 13px;
}

.change-content {
  width: 100%;
  height: calc(100% - 60px);
  /* background-color: skyblue; */
}

.el-input,
.el-button {
  font-size: 13px;
}

/* 合计行整体样式修改开始 */
.el-table /deep/ .el-table__footer-wrapper tbody td,
.el-table /deep/ .el-table__fixed-footer-wrapper tbody td {
  background-color: #fff1d4;
}

.el-table /deep/ tbody tr:hover>td {
  background-color: #fff1d4;
}
<<<<<<< HEAD
=======

#contact-table {
  border-collapse: collapse;
  text-align: center;
}

#contact-table th,
#contact-table td {
  border: 1px solid gray;
  padding: 0px;
}
>>>>>>> 6be95d2b3200ab6fbb17d1e0a5a9b367f780cc8e
</style>